// pages/classify/classify.js

import {request} from "../../utils/https"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    classifyList:[],
  },
  clickBtn(e){
    let _self = this;
    let {index} = e.currentTarget.dataset;
    for(let shopindex in _self.data.classifyList){
      if(shopindex == index){
        _self.data.classifyList[shopindex].ischeck = true;
        _self.data.classifyList[shopindex].color = 'grey';
      }else{
        _self.data.classifyList[shopindex].ischeck = false;
        _self.data.classifyList[shopindex].color = '';
      }
    }
    _self.setData({classifyList:_self.data.classifyList})
  },
  productBtn(e){
    let _self = this;
    let {index,iindex} = e.currentTarget.dataset;
    for(let shopindex in _self.data.classifyList){
      if(shopindex == index){
        _self.data.classifyList[shopindex].ischeck = true;
        _self.data.classifyList[shopindex].color = 'grey';
        for(let goodsindex in _self.data.classifyList[shopindex].product_list){
          if(goodsindex == iindex){
            _self.data.classifyList[shopindex].product_list[goodsindex].ischeck = true;
            _self.data.classifyList[shopindex].product_list[goodsindex].color = 'skyblue';
          }else{
            _self.data.classifyList[shopindex].product_list[goodsindex].ischeck = false;
            _self.data.classifyList[shopindex].product_list[goodsindex].color = '';
          }
        }
      }else{
        _self.data.classifyList[shopindex].ischeck = false;
        _self.data.classifyList[shopindex].color = '';
        for(let goodsindex in _self.data.classifyList[shopindex].product_list){
            _self.data.classifyList[shopindex].product_list[goodsindex].ischeck = false;
            _self.data.classifyList[shopindex].product_list[goodsindex].color = '';
        }
      }
    }
    _self.setData({classifyList:_self.data.classifyList})
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
      let _self = this;
      let classifyList = _self.data.classifyList;
      let data = {
  
      }
      request(
        "home/floordata",
        data,
        "GET",
        function(res){
         classifyList = res.data.message;
         _self.setData({
          classifyList:classifyList.map(item=>{
            return{
              ...item,
              ischeck:false,
              color:'',
              product_list:item.product_list.map(goodsitem=>{
                return{
                  ...goodsitem,
                  ischeck:false,
                  color:''
                }
              })
            }
          })
         })
        }
      )
  },

 
})